<template>
	<view class="content">
		<view class="start" @tap="startClick">
			开始
		</view>
		<!-- <image class="logo" src="/static/logo.png"></image> -->
		<view class="list">
			<view class="list_item" v-for="(item, index) of roleTtypeData">
				<text class="number">{{index + 1}}</text>
				<view class="">{{item.name}}</view>
			</view>
		</view>
		
		<view class="" v-if="myId">
			你的身份是 <text>{{myId}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				roleTtypeData: [],
				myId: null
			}
		},
		onLoad() {

		},
		mounted() {
			this.getRoomList()
		},
		methods: {
			// 洗牌算法
			washCard (cards) {
			  var cardsTmp = []
			  var len = cards.length
			  for (var i=0; i<len; i++) {
			    var index = Math.floor(Math.random()*(len-i))
			    cardsTmp.push(cards[index])
			    cards.splice(index, 1)
			  }
			  cards = cardsTmp
			  return cards
			},
			// 获取狼人杀角色
			async getRoomList() {
				await this.$Api.Home.getRoomList().then(res => {
					this.roleTtypeData = res
					this.roleTtypeData = this.washCard(this.roleTtypeData)
					this.$forceUpdate()
				})
			},
			// 点击开始
			startClick() {
				
			}
		}
	}
</script>

<style lang="scss">
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
	.start {
		margin-top: 30rpx;
		color: #1e6ceb;
	}
	.list {
		margin-top: 60rpx;
		width: calc(100% - 40rpx);
		display: flex;
		flex-wrap: wrap;
		&_item {
			width: 50%;
			display: flex;
			align-items: center;
			justify-content: center;
			height: 100rpx;
			border: 1rpx solid red;
			border-radius: 10rpx;
			box-sizing: border-box;
			margin-bottom: 10rpx;
			position: relative;
			.number {
				position: absolute;
				top: 0;
				left: 10rpx;
			}
		}
		&_item:nth-child(2n+1) {
			width: calc(50% - 40rpx);
			margin-right: 40rpx;
		}
	}
	
</style>
